#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from flask import Blueprint,render_template
from sqlalchemy import or_
from ..database import Article
from ..secure import login_required


bp = Blueprint('beginner', __name__, url_prefix="/beginner")
@bp.route('/')
@bp.route("/<int:page>/")
def index(page=1):

    words = ["%Python%", "%Django%",r"%flask%",r"%scrapy%","%numpy%"]
    rule = or_(*[Article.tag.like(kw) for kw in words],
        *[Article.content.like("%"+kw+"%") for kw in words],
        *[Article.title.like("%"+kw+"%") for kw in words])


    url_for = "beginner.index"

    pagination = Article.query.filter(rule).paginate(page=page,per_page=10)

    return render_template('/pages/index.html', data=pagination, url=url_for)
